package com.x.compute.example;

import com.x.compute.common.util.ComputeUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 简单计算示例
 * @author xuxin
 */
public class SimpleExample {

    public static void main(String[] args) {
        Map<String, Object> params = new HashMap<>();
        //基础计算
        String expression = "1+1";
        System.out.println(expression + "  =  " + ComputeUtils.executeNumber(params, expression));
        expression = "3-1";
        System.out.println(expression + "  =  " + ComputeUtils.executeNumber(params, expression));
        expression = "3*2";
        System.out.println(expression + "  =  " + ComputeUtils.executeNumber(params, expression));
        expression = "10/5";
        System.out.println(expression + "  =  " + ComputeUtils.executeNumber(params, expression));
        expression = "10%3";
        System.out.println(expression + "  =  " + ComputeUtils.executeNumber(params, expression));
        //幂计算
        expression = "2**3";
        System.out.println(expression + "  =  " + ComputeUtils.executeNumber(params, expression));
        //支持百分号计算
        expression = "100*10%";
        System.out.println(expression + "  =  " + ComputeUtils.executeNumber(params, expression));
        //字符串拼接
        expression = "'hello'+'World'";
        System.out.println(expression + "  =  " + ComputeUtils.executeString(params, expression));
        //逻辑运算
        expression = "10==3";
        System.out.println(expression + "  =  " + ComputeUtils.executeBoolean(params, expression));
        expression = "10!=3";
        System.out.println(expression + "  =  " + ComputeUtils.executeBoolean(params, expression));
        expression = "10>3";
        System.out.println(expression + "  =  " + ComputeUtils.executeBoolean(params, expression));
        expression = "10>=3";
        System.out.println(expression + "  =  " + ComputeUtils.executeBoolean(params, expression));
        expression = "10<3";
        System.out.println(expression + "  =  " + ComputeUtils.executeBoolean(params, expression));
        expression = "10<=3";
        System.out.println(expression + "  =  " + ComputeUtils.executeBoolean(params, expression));
        //位运算
        expression = "9 & 5";
        System.out.println(expression + "  =  " + ComputeUtils.executeNumber(params, expression));
        expression = "9 | 5";
        System.out.println(expression + "  =  " + ComputeUtils.executeNumber(params, expression));
        expression = "9 ^ 5";
        System.out.println(expression + "  =  " + ComputeUtils.executeNumber(params, expression));
        expression = "9<<1";
        System.out.println(expression + "  =  " + ComputeUtils.executeNumber(params, expression));
        expression = "9>>1";
        System.out.println(expression + "  =  " + ComputeUtils.executeNumber(params, expression));
    }
}
